package com.jt.sp03.controller;

import com.jt.sp01.entity.User;
import com.jt.sp01.service.UserService;
import com.jt.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户controller
 * @author 郭鲁政
 */
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 根据ID获取User
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/{userId}")
    public JsonResult<User> getUser(@PathVariable(name = "userId") Integer userId){
        User user = userService.getUser(userId);
        return JsonResult.ok(user);
    }

    /**
     * 根据用户id添加积分
     * @param userId
     * @param score
     * @return
     */
    @GetMapping("/{userId}/score")
    public JsonResult<?> addScore(@PathVariable(name = "userId")Integer userId,Integer score){
        userService.addScore(userId, score);
        return JsonResult.ok().data("业务执行成功");
    }
    @GetMapping("/favicon.ico")
    public void favicon(){}

}
